from urllib import parse

import requests


class Api_request:

    def __init__(self):
        self.session = requests.sessions.session()

    def http_request(self, method, url, data=None, json=None):
        method = method.upper()

        if type(data) == str:
            data = eval(data)

        if method == 'GET':
            resp = self.session.request(method=method, url=url, params=data)
        elif method == 'POST':
            if json:
                resp = self.session.request(method=method, url=url, json=json)
            else:
                resp = self.session.request(method=method, url=url, data=data)
        elif method == 'DELETE':
            pass
        elif method == 'PUT':
            pass
        else:
            print('没有这个请求方式')
        return resp

    def close(self):
        self.session.close()


if __name__ == '__main__':
    re = Api_request()
    data1 = re.http_request("POST", "http://work.yayi360.com/account/userlogin",
                            "{'mobile':'18971455884','password':'009900','loginType':'1'}")

    data2 = re.http_request("POST", "http://work.yayi360.com/order/clinic/getorderlist",
                            "{'cdate':'2020-06-22','edate':'2020-06-22','pagesize':'100','pageno':'1'}")

    order_list = []
    for i in range(0, len(data2.json()['list'])):
        need_value = data2.json()['list'][i]['orderno']
        order_list.append(need_value)
    print(order_list, type(order_list))
